package com.mgq.generic;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @author MaGuangQi
 * @description
 * @date 2021-12-26 11:29
 **/
public class TestAnimal {
    public static void main(String[] args) {
        //TreeSet的构造方法就是类型通配符的下限
        TreeSet<Cat> animals = new TreeSet<>(new Compare2());
        animals.add(new MiniCat("addd", 22, 1));
        animals.add(new MiniCat("sddfadd", 26, 1));
        animals.add(new MiniCat("erwdd", 234, 1));
        for (Animal animal : animals) {
            System.out.println(animal);
        }
    }

}

class Compare1 implements Comparator<Animal> {

    @Override
    public int compare(Animal o1, Animal o2) {
        return o1.getName().compareTo(o2.getName());
    }
}
class Compare2 implements Comparator<Cat> {


    @Override
    public int compare(Cat o1, Cat o2) {
        return o1.getAge()-o2.getAge();
    }
}
class Compare3 implements Comparator<MiniCat> {


    @Override
    public int compare(MiniCat o1, MiniCat o2) {
        return o1.getLevel()-o2.getLevel();
    }
}
